package com.north.light.libmediapreview.manager;

import android.widget.ImageView;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * author:li
 * date:2022/9/25
 * desc:外部图片加载管理类
 */
public class PreviewLoadPicManager implements Serializable {
    private List<PreviewLoadPicListener> mListener = new ArrayList<>();

    public static class SingleHolder implements Serializable {
        public static PreviewLoadPicManager mInstance = new PreviewLoadPicManager();
    }

    public static PreviewLoadPicManager getInstance() {
        return SingleHolder.mInstance;
    }

    //加载图片--内部调用
    public <T extends ImageView> void load(String url, T iv) {
        for (PreviewLoadPicListener pic : mListener) {
            pic.loadPic(url, iv);
        }
    }

    //加载监听
    public void setListener(PreviewLoadPicListener listener) {
        if (listener == null) {
            return;
        }
        mListener.add(listener);
    }

    public void removeListener(PreviewLoadPicListener listener) {
        if (listener == null) {
            return;
        }
        mListener.remove(listener);
    }
}
